home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Bitmap Libraries 2.0 / BitMap.h < prev    next >
Text File  |  1996-07-08  |  8KB  |  294 lines

  1. /* File BitMap.h Copyright (C) 1996 by John R. Montbriand.  All Rights Reserved. */
  2.  
  3. #ifndef __BITMAP__
  4. #define __BITMAP__
  5.  
  6. /* File BitMap.h
  7.  
  8.     Copyright (C) 1996 by John Montbriand.  All Rights Reserved.
  9.     
  10.     Distribute freely in areas where the laws of copyright apply.
  11.     
  12.     Use at your own risk.
  13.     
  14.     Do not distribute modified copies.
  15.     
  16.     These various BitMap libraries are for free!
  17.     
  18.     See the file BitMap.txt for details.
  19.     
  20. */
  21.  
  22. #include <Types.h>
  23. #include <QuickDraw.h>
  24.  
  25. #ifdef __cplusplus
  26. extern "C" { 
  27. #endif
  28.  
  29.  
  30.  
  31. /* version number for this implementation */
  32.  
  33. #define kBitMapVersion 2
  34.  
  35.  
  36.  
  37. /* NewBitMap creates a new bitmap pointer with the requested
  38.     dimensions.  The raster data is initialized to zeros and the
  39.     returned pointer is unlocked.  If there is not enough memory
  40.     to allocate the bitmap, NewBitMap will return NULL.  Initially,
  41.     the baseAddr field is set to NULL. */
  42.     
  43. BitMap* NewBitMap(short width, short height);
  44.  
  45.  
  46.  
  47. /* KillBitMap disposes of a bitmap pointer allocated by one of:
  48.  
  49.     NewMacPaintBitMap, NewBitMap, RotateRight, RotateLeft, FlipVertical,
  50.     FlipHorizontal, RotateBitMap, DuplicateBitMap, PaintBucketBitMap,
  51.     LassoBitMap, PICTToBitMap, BitMapAND, BitMapOR, BitMapXOR,
  52.     BitMapNOT, or StringToBitMap.
  53.     
  54.     It's your general all purpose bitmap pointer disposal function. */
  55.  
  56. void KillBitMap(BitMap* bits);
  57.  
  58.  
  59.  
  60. /* RotateRight creates a new bitmap containing the image
  61.     stored in the parameter bitmap pointer rotated 90 degrees
  62.     to the right.  The resulting bitmap is appropriately sized:
  63.     i.e. if the source bitmap is 100 pixels wide and 200 pixels tall,
  64.     then the result bitmap pointer will be 200 pixels wide and 100
  65.     pixels tall.   */
  66.     
  67. BitMap* RotateRight(BitMap* bits);
  68.  
  69.  
  70.  
  71. /* RotateLeft creates a new bitmap containing the image
  72.     stored in the parameter bitmap pointer rotated 90 degrees
  73.     to the left.  The resulting bitmap is appropriately sized:
  74.     i.e. if the source bitmap is 100 pixels wide and 200 pixels tall,
  75.     then the result bitmap pointer will be 200 pixels wide and 100
  76.     pixels tall.   */
  77.     
  78. BitMap* RotateLeft(BitMap* bits);
  79.  
  80.  
  81.  
  82. /* FlipVertical creates a new bitmap containing the image
  83.     stored in the parameter bitmap pointer flipped upside
  84.     down.  The resulting bitmap will be the same size as
  85.     the original image.  */
  86.     
  87. BitMap* FlipVertical(BitMap* bits);
  88.  
  89.  
  90.  
  91. /* FlipHorizontal creates a new bitmap containing the image
  92.     stored in the parameter bitmap pointer flipped horizontally.
  93.     The resulting bitmap will be the same size as the original image.  */
  94.     
  95. BitMap* FlipHorizontal(BitMap* bits);
  96.  
  97.  
  98.  
  99. /* RotateBitMap creates a new bitmap containing the image from
  100.     the parameter bitmap pointer rotated angle degrees about the
  101.     center (cx, cy).  The resultant bitmap will have the same dimensions
  102.     as the parameter bitmap regardless of the angle specified. */
  103. BitMap* RotateBitMap(BitMap* bits, short cx, short cy, float angle);
  104.  
  105.  
  106.  
  107. /* IRotateBitMap is identical to RotateBitMap except it accepts an
  108.     integer variable in the angle parameter. */
  109. BitMap* iRotateBitMap(BitMap* bits, short cx, short cy, short angle);
  110.  
  111.  
  112. /* DuplicateBitMap creates a copy of the bitmap parameter. */
  113.  
  114. BitMap* DuplicateBitMap(BitMap* bits);
  115.  
  116.  
  117.  
  118. /* PaintBucketBitMap works like the paint bucket tool found in
  119.     most graphical applications.  It calls the routine SeedFill
  120.     and to fill in the image information in the resulting bitmap
  121.     pointer. */
  122.  
  123. BitMap* PaintBucketBitMap(BitMap* bits, short h, short v);
  124.  
  125.  
  126.  
  127. /* LassoBitMap works like the lasso bucket tool found in
  128.     most graphical applications.  It calls the routine CalcMask
  129.     and to fill in the image information in the resulting bitmap
  130.     pointer. */
  131.  
  132. BitMap* LassoBitMap(BitMap* bits);
  133.  
  134.  
  135. /* TraceBitMap performs the 'trace edges' command found in
  136.     many graphical applications returning a new bitmap
  137.     containing the traced image. */
  138.  
  139. BitMap* TraceBitMap(BitMap* bits);
  140.  
  141.  
  142. /* EqualBitMaps returns true if the two bitmaps are identical in size
  143.     and image content. */
  144.  
  145. Boolean EqualBitMaps(BitMap* a, BitMap* b);
  146.  
  147.  
  148. /* PICTToBitMap creates a new bitmap pointer the using the size
  149.     information provided in the QuickDraw picture pointer parameter
  150.     and draws the picture in the bitmap before returning the bitmap. */
  151.     
  152. BitMap* PICTToBitMap(PicHandle pic);
  153.  
  154.  
  155.  
  156. /* BitMapToPICT returns a QuickDraw picture that will draw the
  157.     image stored in the bitmap.  BitMapToPICT is the inverse
  158.     of PICTToBitMap. */
  159.     
  160. PicHandle BitMapToPICT(BitMap* bits);
  161.  
  162.  
  163.  
  164. /* BitMapAND logically ANDs the raster data of two bitmap pointers
  165.     returning a new bitmap pointer containing the result.  The two
  166.     parameter bitmaps must have identical dimensions. */
  167.     
  168. BitMap* BitMapAND(BitMap* a, BitMap* b);
  169.  
  170.  
  171.  
  172. /* BitMapOR logically ORs the raster data of two bitmap pointers
  173.     returning a new bitmap pointer containing the result.  The two
  174.     parameter bitmaps must have identical dimensions. */
  175.  
  176. BitMap* BitMapOR(BitMap* a, BitMap* b);
  177.  
  178.  
  179.  
  180. /* BitMapXOR logically XORs the raster data of two bitmap pointers
  181.     returning a new bitmap pointer containing the result.  The two
  182.     parameter bitmaps must have identical dimensions. */
  183.     
  184. BitMap* BitMapXOR(BitMap* a, BitMap* b);
  185.  
  186.  
  187.  
  188. /* BitMapNOT returns a new bitmap pointer containing the inverse
  189.     of the raster image contained in the bitmap pointer a. */
  190.     
  191. BitMap* BitMapNOT(BitMap* a);
  192.  
  193.  
  194.  
  195. /* BitMapTest tests the value of the pixel at the location (h,v)
  196.     returning true if the pixel is 1, and false if the pixel is zero. */
  197.     
  198. Boolean BitMapTest(BitMap* bits, short h, short v);
  199.  
  200.  
  201.  
  202. /* BitMapSet sets the value of the pixel at the location (h,v) to 1. */
  203.  
  204. void BitMapSet(BitMap* bits, short h, short v);
  205.  
  206.  
  207.  
  208. /* BitMapClear clears the value of the pixel at the location (h,v) to 0. */
  209.  
  210. void BitMapClear(BitMap* bits, short h, short v);
  211.  
  212.  
  213.  
  214. /* BitMapToggle inverts the value of the pixel at the location (h,v)
  215.     returning true if the pixel is set to 1 or false if the pixel
  216.     is set to 0. */
  217.  
  218. Boolean BitMapToggle(BitMap* bits, short h, short v);
  219.  
  220.  
  221.  
  222.  
  223. /* BitMapPort data structure managed by the routines NewBMP
  224.     and DisposeBMP.  You should never have to access the fields of this
  225.     record directly as it's all taken care of by NewBMP and DisposeBMP. */
  226.  
  227. typedef struct {
  228.     GrafPort gp;        /* the grafport record for drawing into the bitmap */
  229.     GrafPtr gpsave;    /* saved grafport for later restoration */
  230.     BitMap* bits;        /* the bitmap pointer */
  231. } BitMapPort;
  232.  
  233.  
  234.  
  235. /* NewBMP is called by the WithBitMap macro and you should
  236.     never have to call it directly yourself.  What it does is
  237.     it locks the bitmap, saves the original grafport, and creates
  238.     a new grafport suitable for drawing into the bitmap.  NewBMP
  239.     should be followed by a call to DisposeBMP which will restore
  240.     the original grafport, unlock the bitmap, and dispose of the
  241.     new grafport. */
  242.     
  243. BitMapPort* NewBMP(BitMap* bits);
  244.  
  245.  
  246.  
  247. /* DisposeBMP unlocks the bitmap pointer passed to NewBMP, deallocates
  248.     the grafport allocated for it, and restores the original grafport.
  249.     the macro WithBitMap calls this routine automatically and you will
  250.     not normally have to call it directly. */
  251.     
  252. void DisposeBMP(BitMapPort* bmp);
  253.  
  254.  
  255.  
  256. /* WithBitMap is a macro facility that sets up the drawing
  257.     environment such that any drawing commands in the statement
  258.     following the macro instantiation will draw into the bitmap
  259.     provided as the first parameter.
  260.     bits is a bitmap pointer:  BitMap **bits;
  261.     bmp is a bitmap port pointer variable:  BitMapPort* bmp; */
  262.     
  263. #define WithBitMap(bits, bmp) \
  264.     for (bmp = NewBMP(bits); bmp != NULL; DisposeBMP(bmp), bmp = NULL)
  265.  
  266.  
  267.  
  268. /* PlotBitMap provides a simple interface for drawing a bitmap in
  269.     the current grafport.  The bitmap is drawn with the top left corner
  270.     aligned with the point (h,v) using the indicated transfer mode. */
  271.  
  272. void PlotBitMap(BitMap* bits, short h, short v, short mode);
  273.  
  274.  
  275.  
  276. /* StringToBitMap converts the string pointed to by s into a bitmap
  277.     drawing the string onto an appropriately sized bitmap for the
  278.     given font, size, and style(face).  StringToBitMap is useful for
  279.     converting strings to bitmap so rotation can be applied with
  280.     RotateRight or RotateLeft before it is displayed.  StringToBitMap
  281.     preserves the current grafport.  */
  282.     
  283. BitMap* StringToBitMap(short font, short size, short face, StringPtr s);
  284.  
  285.  
  286. #ifdef __cplusplus
  287. };
  288. #endif
  289.  
  290.  
  291. #endif
  292.  
  293. /* end of File BitMap.h */
  294.